package com.ymttest.business.service;

import com.google.gson.JsonArray;
import com.ymatou.iapi.livebuyer.parameter.*;
import com.ymatou.iapi.livebuyer.service.*;
import com.ymatou.iapi.liveseller.parameter.*;
import com.ymatou.iapi.liveseller.service.*;
import com.ymatou.iapi.userservice.parameter.resp.UserInfo2;
import com.ymatou.livevideo.parameter.*;
import com.ymatou.livevideo.service.LiveNotifyCall;
import com.ymatou.livevideo.service.TimNotifyCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymttest.database.model.LiveActivity;
import com.ymttest.database.model.LiveActivityProduct;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import org.apache.http.client.ClientProtocolException;

import java.io.IOException;
import java.util.*;

/************************************************************************************
 * @File name :LiveRoomCallService.java
 * @Author : zhouyi
 * @Date : 2017年10月30日
 * @Copyright : 洋码头
 ************************************************************************************/
public class LiveRoomCallService {
	/**
	 * 直播推流key
	 */
	public static String LiveAntiKey = "7eac8d73ada557988fb1d0ffff89caed";

	/**
	 * 直播API鉴权key
	 */
	public static String LiveApiKey = "f21c3164a0c4e1e2a66748ca3b3c6b25";
	public static String AppId = "1255315550";
	//20181024域名变更 不再用 12808.liveplay.myqcloud.com
	public static String BizId = "12808";
	public static String PlayDomain ="vtestplay.ymatou.com";
	public static String PlaySellerDomain ="vtestplay.ymatou.com";
	public static String ImSdkAppId = "1400046801";
	public static String ImAccountType = "18457";
	// 待确认
	// public static String SdkAppId = "1400046801";
	/**
	 * 审核直播
	 * @param id
	 * @param status
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void AuditLive(Integer id,Integer status) throws ClientProtocolException, IOException {
		AuditLiveBean auditliveBean=new AuditLiveBean();
		AuditLiveCall auditliveCall=new AuditLiveCall();
		auditliveBean.setLiveId(id);
		auditliveBean.setAuditState(status);
		auditliveBean.setOperator("autotest");
		auditliveCall.setData(auditliveBean);
		auditliveCall.callService();			
	}
	/**
	 * 同步直播排名
	 * @param sellerid
	 * @param liveId
	 * @param topnum 排名
	 * @param LiveCategory  * 1箱包手袋榜 2 珠宝配饰榜 3 潮流服饰榜 10美容家居榜
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SyncLivesellerTop(Integer sellerid,Integer liveId,Integer topnum,Integer LiveCategory) throws ClientProtocolException, IOException {
		SyncLiveSellerTopBean synclivesellertopBean=new SyncLiveSellerTopBean();
		SyncLiveSellerTopCall synclivesellertopCall=new SyncLiveSellerTopCall();
		synclivesellertopBean.setSellerId(sellerid);
		synclivesellertopBean.setLiveId(liveId);
		synclivesellertopBean.setTopNum(topnum);
		synclivesellertopBean.setLiveCategory(LiveCategory);
		synclivesellertopCall.setData(synclivesellertopBean);
		synclivesellertopCall.callService();
	}
	/**
	 * 设置直播热度
	 * @param liveId
	 * @param Heat
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void setLiveHeat(Integer liveId,Double Heat) throws ClientProtocolException, IOException {
		SyncLiveHeatBean syncliveheatBean=new SyncLiveHeatBean();
		SyncLiveHeatCall syncliveheatCall=new SyncLiveHeatCall();
		syncliveheatBean.setHeat(Heat);
		syncliveheatBean.setLiveId(liveId);
		syncliveheatCall.setData(syncliveheatBean);
		syncliveheatCall.callService();	
	}
	/**
	 * 查询直播商品列表
	 * @param liveid
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static JsonArray QueryLiveProductIdList(Integer liveid) throws ClientProtocolException, IOException {
		QueryLiveProductIdListBean queryliveproductidlistBean=new QueryLiveProductIdListBean();
		QueryLiveProductIdListCall queryliveproductidlistCall=new QueryLiveProductIdListCall();
		queryliveproductidlistBean.setLiveId(liveid);
		queryliveproductidlistCall.setData(queryliveproductidlistBean);
		queryliveproductidlistCall.callService();		
		return queryliveproductidlistCall.getProductList();
	}
	/**
	 * 订阅秒杀活动
	 * @param userid
	 * @param liveid
	 * @param liveacctivityid
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 * @reutrn liveproducts.get(0).getLiveActivityProductId()
	 */
	public static Integer Subscribeactivity(Integer userid,Integer liveid,Integer liveacctivityid,String productId) throws ClientProtocolException, IOException, InterruptedException {
		LiveRoomWapper LiveRoomWapper=new LiveRoomWapper();
		SubscribeActivityBean subscribeactivityBean=new SubscribeActivityBean();
		SubscribeActivityCall subscribeactivityCall=new SubscribeActivityCall();
		LiveActivity livea = LiveRoomWapper.selectLiveactivityByLiveId(liveid).get(0);
		List<LiveActivityProduct> liveproducts = LiveRoomWapper.selectLiveactivityproduct(livea.getLiveActivityId(), productId);
		subscribeactivityBean.setLiveActivityId(livea.getLiveActivityId());
		subscribeactivityBean.setLiveId(liveid);
		subscribeactivityBean.setUserId(userid);
		subscribeactivityBean.setLiveActivityProductId(liveproducts.get(0).getLiveActivityProductId());
		subscribeactivityCall.setData(subscribeactivityBean);
		subscribeactivityCall.callService();
		return liveproducts.get(0).getLiveActivityProductId();
//		subscribeactivityBean.setLiveActivityId(liveacctivityid);
//		subscribeactivityBean.setLiveId(liveid);
//		subscribeactivityBean.setUserId(userid);
		
	}
	/**
	 * 参考 com.ymatou.livevideo.testcase.Ts_TimNotify	  Tc_TimNotify_010
	 * 
	 * @param groupid
	 * @param uid
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void CallbackAfterSendMsg(String groupid, Integer uid,String content) throws InterruptedException, ClientProtocolException, IOException {
		Logger.comment("用户发消息回调");
		TimNotifyReq timNotifyReq = new TimNotifyReq();
		timNotifyReq.setClientIP(TestDataManager.getRandomIp());
		timNotifyReq.setOptPlatform("Web");
		timNotifyReq.setSdkAppid(LiveRoomCallService.ImSdkAppId);
		timNotifyReq.setCallbackCommand("Group.CallbackAfterSendMsg");
		timNotifyReq.setContenttype(null);
		timNotifyReq.setTimNotifyType(null);
		TimNotifyCall timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
		SyncTimMsgCallBackReq timnotifyBean=new SyncTimMsgCallBackReq();
		timnotifyBean.setCallbackCommand("Group.CallbackAfterSendMsg");
		timnotifyBean.setMsgSeq(YMTDateUtil.getDate().getTime());
		timnotifyBean.setMsgTimestamp(YMTDateUtil.getDate().getTime()/1000);
		timnotifyBean.setFromAccount(uid.toString());
		timnotifyBean.setGourpId(groupid);
		List<TimChatMessageBody> msgBody=new ArrayList<>();
		//TIMTextElem
		TimChatMessageBody TIMTextElem=new TimChatMessageBody();
		TIMTextElem.setMsgType("TIMTextElem");
		TimChatMessageContent msgContent=new TimChatMessageContent();
//		String content="relmsg";
		msgContent.setText("{\"msg\":\""+content+"\"}");
		TIMTextElem.setMsgContent(msgContent);
		msgBody.add(TIMTextElem);
		//TIMTextElem
		TimChatMessageBody TIMCustomElem=new TimChatMessageBody();
		TIMCustomElem.setMsgType("TIMCustomElem");
		TimChatMessageContent cusMsgContent=new TimChatMessageContent();
		String logoimg="http://www.ymatou.com";
		UserInfo2 ui=JUserCallService.GetUserInfo(uid);
		cusMsgContent.setData("{\"headPic\":\""+logoimg+"\""
				+ ",\"userAction\":1,\"userId\":\""+uid+"\",\"nickName\":\""+ui.getLoginId()+"\",\"buyerLevel\":\""+ui.getUserLevel()+"\"}");
		TIMCustomElem.setMsgContent(cusMsgContent);
		msgBody.add(TIMCustomElem);
		
		timnotifyBean.setMsgBody(msgBody);
		timnotifyBean.setType("AVChatRoom");
		timnotifyCall.setData(timnotifyBean);
		timnotifyCall.callService();		
		Thread.sleep(10);
	}
	public static void CallbackAfterSendMsg(String groupid, Integer uid,String content,String cusMsgContentdata) throws InterruptedException, ClientProtocolException, IOException {
		Logger.comment("用户发消息回调");
		TimNotifyReq timNotifyReq = new TimNotifyReq();
		timNotifyReq.setClientIP(TestDataManager.getRandomIp());
		timNotifyReq.setOptPlatform("Web");
		timNotifyReq.setSdkAppid(LiveRoomCallService.ImSdkAppId);
		timNotifyReq.setCallbackCommand("Group.CallbackAfterSendMsg");
		timNotifyReq.setContenttype(null);
		timNotifyReq.setTimNotifyType(null);
		TimNotifyCall timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
		SyncTimMsgCallBackReq timnotifyBean=new SyncTimMsgCallBackReq();
		timnotifyBean.setCallbackCommand("Group.CallbackAfterSendMsg");
		timnotifyBean.setMsgSeq(YMTDateUtil.getDate().getTime());
		timnotifyBean.setMsgTimestamp(YMTDateUtil.getDate().getTime()/1000);
		timnotifyBean.setFromAccount(uid.toString());
		timnotifyBean.setGourpId(groupid);
		List<TimChatMessageBody> msgBody=new ArrayList<>();
		//TIMTextElem
		TimChatMessageBody TIMTextElem=new TimChatMessageBody();
		TIMTextElem.setMsgType("TIMTextElem");
		TimChatMessageContent msgContent=new TimChatMessageContent();
//		String content="relmsg";
		msgContent.setText("{\"msg\":\""+content+"\"}");
		TIMTextElem.setMsgContent(msgContent);
		msgBody.add(TIMTextElem);
		//TIMTextElem
		TimChatMessageBody TIMCustomElem=new TimChatMessageBody();
		TIMCustomElem.setMsgType("TIMCustomElem");
		TimChatMessageContent cusMsgContent=new TimChatMessageContent();
		String logoimg="http://www.ymatou.com";
		UserInfo2 ui=JUserCallService.GetUserInfo(uid);
		cusMsgContent.setData(cusMsgContentdata);
		TIMCustomElem.setMsgContent(cusMsgContent);
		msgBody.add(TIMCustomElem);
		
		timnotifyBean.setMsgBody(msgBody);
		timnotifyBean.setType("AVChatRoom");
		timnotifyCall.setData(timnotifyBean);
		timnotifyCall.callService();		
		Thread.sleep(10);
	}
	/**
	 * 修改用户在线状态
	 * 
	 * @param uid
	 * @param type
	 *            1在线 0 离线 2 断开
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void ChargeIMOnlineType(String uid, int type) throws InterruptedException, ClientProtocolException, IOException {
		Logger.comment("修改腾讯IM在线状态");
		TimNotifyReq timNotifyReq = new TimNotifyReq();
		timNotifyReq.setCallbackCommand("State.StateChange");
		timNotifyReq.setClientIP(TestDataManager.getRandomIp());
		timNotifyReq.setOptPlatform("Web");
		timNotifyReq.setSdkAppid(LiveRoomCallService.ImSdkAppId);
		timNotifyReq.setTimNotifyType("StateChange");
		timNotifyReq.setContenttype("json");
		TimNotifyCall timnotifyCall = new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true, false));
		TimNotifyBean timnotifyBean = new TimNotifyBean();
		timnotifyBean.setCallbackCommand("State.StateChange");
		StateChangeInfo Info = new StateChangeInfo();
		if (type == 1) {
			Info.setAction("Login");
			Info.setReason("Register");
		} else if(type == 2){
			Info.setAction("Disconnect");
			Info.setReason("LinkClose");
		}else {
			Info.setAction("Logout");
			Info.setReason("TimeOut");
		}
		Info.setTo_Account(uid);
		timnotifyBean.setInfo(Info);
		timnotifyCall.setData(timnotifyBean);
		timnotifyCall.callService();
	}
	/**"修改腾讯IM在线状态"
	 * @param uid
	 * @param type  1在线 0下线 2断开
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void ChargeGlobalIMOnlineType(String uid, int type) throws InterruptedException, ClientProtocolException, IOException {
		Logger.comment("修改腾讯IM在线状态");
		TimNotifyReq timNotifyReq = new TimNotifyReq();
		timNotifyReq.setCallbackCommand("State.StateChange");
		timNotifyReq.setClientIP(TestDataManager.getRandomIp());
		timNotifyReq.setOptPlatform("Web");
		timNotifyReq.setSdkAppid(LiveRoomCallService.ImSdkAppId);
		timNotifyReq.setTimNotifyType("StateChange");
		timNotifyReq.setContenttype("json");
		TimNotifyCall timnotifyCall = new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true, false));
		TimNotifyBean timnotifyBean = new TimNotifyBean();
		timnotifyBean.setCallbackCommand("State.StateChange");
		StateChangeInfo Info = new StateChangeInfo();
		if (type == 1) {
			Info.setAction("Login");
			Info.setReason("Register");
		} else if(type == 2){
			Info.setAction("Disconnect");
			Info.setReason("LinkClose");
		}else {
			Info.setAction("Logout");
			Info.setReason("TimeOut");
		}
		Info.setTo_Account("global-"+uid);
		timnotifyBean.setInfo(Info);
		timnotifyCall.setData(timnotifyBean);
		timnotifyCall.callService();
	}
	/**
	 * 发布直播状态 用于推送直播在线人数/比心数 定时调用
	 * 
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void PublishLiveStatCall(Integer liveid) throws InterruptedException, ClientProtocolException, IOException {
		Logger.comment("推送直播状态");
		Thread.sleep(1500);
		PublishLiveStatBean PublishLiveStatBean = new PublishLiveStatBean();
		PublishLiveStatCall PublishLiveStatCall = new PublishLiveStatCall();
		if (liveid != null) {
			PublishLiveStatBean.setLiveId(liveid);
			PublishLiveStatCall.setData(false, PublishLiveStatBean);
		}
		PublishLiveStatCall.callService();
		Thread.sleep(3000);
	}

	/**
	 * 查询房间信息
	 * 
	 * @param id
	 * @return
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static LiveRoomInfo getRoomInfo(int id) throws InterruptedException, ClientProtocolException, IOException {
		Logger.comment("查询房间信息");
		QueryLiveRoomBean queryliveroomBean = new QueryLiveRoomBean();
		QueryLiveRoomCall queryliveroomCall = new QueryLiveRoomCall();
		queryliveroomBean.setLiveId(id);
		queryliveroomCall.setData(false, queryliveroomBean);
		queryliveroomCall.callService();
		return queryliveroomCall.getLiveRoomInfo();
	}

	/**
	 * 初始化tx回调退断流信息
	 * 
	 * @param id
	 * @param event_type
	 *            1推流 0断流
	 * @return
	 * @throws Exception
	 *             真实报文
	 *             {"app":"12808.livepush.myqcloud.com","appId":"1255315550","appname":"live","channel_id":"12808_SIT1_235","errcode":1,"errmsg":"recv
	 *             rtmp
	 *             deleteStream","event_type":0,"node":"100.67.177.19","requestId":"781eaafd69764f7fa9f97d08e5c612cb","sequence":"1418989456100673054","sign":"5bbc740031c41e44d62c48058e4de804","stream_id":"12808_SIT1_235","stream_param":"txSecret=97f7e30da2082d7eefcad89371c04181&txTime=59F08C74","t":"1509006840","update_time":0,"user_ip":"114.80.87.210"}
	 */
	public static StreamLiveNotifyBean initStreamLiveNotifyBean(Integer id, int event_type) throws Exception {
		String sequence = TestDataManager.getRandomNum(9);
		Long ltime = YMTDateUtil.getDate().getTime();
		String time = Long.toHexString(ltime);
		StreamLiveNotifyBean streamlivenotifyBean = new StreamLiveNotifyBean();
		streamlivenotifyBean.setChannel_id(BizId + "_" + EnvSetup.getEnv() + "_" + id);
		streamlivenotifyBean.setStream_id(BizId + "_" + EnvSetup.getEnv() + "_" + id);
		streamlivenotifyBean.setT(String.valueOf(YMTDateUtil.getDate().getTime()));
		streamlivenotifyBean.setEvent_type(event_type);
		streamlivenotifyBean.setSign(TestDataManager.getMD5(id.toString().getBytes()));
		streamlivenotifyBean.setApp(BizId + ".livepush.myqcloud.com");
		streamlivenotifyBean.setNode(TestDataManager.getRandomIp());
		streamlivenotifyBean.setSequence(sequence);
		streamlivenotifyBean.setSign(TestDataManager.getMD5((LiveApiKey + ltime.toString()).getBytes()));
		streamlivenotifyBean.setT(ltime.toString());
		streamlivenotifyBean.setStream_param("bizid=" + BizId + "&txSecret="
				+ TestDataManager.getMD5((LiveRoomCallService.LiveAntiKey + LiveRoomCallService.BizId + "_" + id + Long.toHexString(ltime)).getBytes()) + "&txTime=" + time);
		return streamlivenotifyBean;
	}

	/**
	 * 初始化录播回调报文
	 * 
	 * @param id
	 * @param event_type
	 * @return
	 * @throws Exception
	 */
	public static RecLiveNotifyBean initRecLiveNotifyBean(Integer id, int event_type) throws Exception {
		String sequence = TestDataManager.getRandomNum(9);
		Long ltime = YMTDateUtil.getDate().getTime();
		String time = Long.toHexString(ltime);
		RecLiveNotifyBean reclivenotifyBean = new RecLiveNotifyBean();
		reclivenotifyBean.setChannel_id(BizId + "_" + EnvSetup.getEnv() + "_" + id);
		reclivenotifyBean.setStream_id(BizId + "_" + EnvSetup.getEnv() + "_" + id);
		reclivenotifyBean.setT(String.valueOf(YMTDateUtil.getDate().getTime()));
		reclivenotifyBean.setEvent_type(event_type);
		reclivenotifyBean.setSign(TestDataManager.getMD5(id.toString().getBytes()));
		reclivenotifyBean.setSign(TestDataManager.getMD5((LiveApiKey + ltime.toString()).getBytes()));
		reclivenotifyBean.setT(ltime.toString());
		reclivenotifyBean.setStream_param("bizid=" + BizId + "&txSecret="
				+ TestDataManager.getMD5((LiveRoomCallService.LiveAntiKey + LiveRoomCallService.BizId + "_" + id + Long.toHexString(ltime)).getBytes()) + "&txTime=" + time);
		reclivenotifyBean.setAppid(AppId);
		reclivenotifyBean.setDuration("120");
		reclivenotifyBean.setEnd_time(String.valueOf(YMTDateUtil.getBeforeOrNextDate(-1).getTime()).substring(0, 10));
		reclivenotifyBean.setFile_format("hls");
		reclivenotifyBean.setFile_id(TestDataManager.getRandomUUID().toString().replaceAll("-", "").substring(0,20));
		reclivenotifyBean.setFile_size("20000");
		reclivenotifyBean.setStart_time(String.valueOf(YMTDateUtil.getBeforeOrNextDate(0).getTime()).substring(0, 10));
		String video_id = AppId + "_" + TestDataManager.getRandomNum(27);
		reclivenotifyBean.setVideo_url("http://" + AppId + ".vod2.myqcloud.com/" + video_id + "/playlist.m3u8");
		reclivenotifyBean.setVideo_id(video_id);
		return reclivenotifyBean;
	}

	/**
	 * 添加脏字管理
	 * 
	 * @param dirtyword
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void AddDirtyWords(String dirtyword) throws ClientProtocolException, IOException {
		Logger.comment("添加脏字列表");
		List<String> dirtyWords = Arrays.asList(dirtyword);
		AddDirtyWordsBean adddirtywordsBean = new AddDirtyWordsBean();
		AddDirtyWordsCall adddirtywordsCall = new AddDirtyWordsCall();
		adddirtywordsBean.setDirtyWords(dirtyWords);
		adddirtywordsBean.setOperator("洋码头测试");
		adddirtywordsCall.setData(false, adddirtywordsBean);
		adddirtywordsCall.callService();
	}

	/**
	 * 强制系统关闭 会修改直播时间和状态
	 * 
	 * @param liveid
	 * @throws IOException
	 * @throws ClientProtocolException
	 * @throws InterruptedException
	 */
	public static void SysCloseLive(Integer liveid) throws ClientProtocolException, IOException, InterruptedException {
		LiveRoomWapper liveRoomWapper = new LiveRoomWapper();
		liveRoomWapper.updateLiveRoomTime(YMTDateUtil.getBeforeOrNextMunite(-100), YMTDateUtil.getBeforeOrNextMunite(-50),YMTDateUtil.getBeforeOrNextMunite(-50), liveid);
		if (liveRoomWapper.selectLiveRoomById(liveid).getLiveStatus() == 2) {
			liveRoomWapper.updateLiveRoomPushStatus(liveid, 3);
		}
		SysCloseLiveCall syscloseliveCall = new SysCloseLiveCall();
		SysCloseLiveBean syscloseliveBean = new SysCloseLiveBean();
		syscloseliveCall.setData(syscloseliveBean);
		syscloseliveCall.callService();
		Thread.sleep(3000);
	}

	/**
	 * 查询脏字列表
	 * 
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static JsonArray QueryDirtyWords() throws ClientProtocolException, IOException {
		Logger.comment("查询脏字列表");
		QueryDirtyWordsBean querydirtywordsBean = new QueryDirtyWordsBean();
		QueryDirtyWordsCall querydirtywordsCall = new QueryDirtyWordsCall();
		querydirtywordsBean.setAppId("www.ymatou.com");
		querydirtywordsBean.setPageIndex(1);
		querydirtywordsBean.setPageSize(50);
		querydirtywordsCall.setData(false, querydirtywordsBean);
		querydirtywordsCall.callService();
		return querydirtywordsCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("results");
	}

	/**
	 * 第三方通知
	 * 
	 * @param streamlivenotifyBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void LiveNotify(LiveNotifyBean streamlivenotifyBean) throws ClientProtocolException, IOException {
		Logger.comment("第三方通知:Event_type:" + streamlivenotifyBean.getEvent_type());
		LiveNotifyCall livenotifyCall = new LiveNotifyCall();
		livenotifyCall.setData(false, streamlivenotifyBean);
		Map mock=new HashMap();
//		mock:mock-enable
		mock.put("mock", "mock-enable");
		mock.put("mockId-1", TestDataManager.getRandomUUID().toString());
		mock.put("mockApi-1", "livevideo-processMediaByProcedure-Normal");
		PayGateWayCallService.addMock(livenotifyCall, mock);
		livenotifyCall.callService();
	}

	/**
	 * 创建聊天室groupid
	 * 
	 * @param groupname
	 * @return groupid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static String CreateGroup(String groupname,Integer sellerid) throws ClientProtocolException, IOException {
		Logger.comment("创建群:groupname:" + groupname);
		CreateGroupBean creategroupBean = new CreateGroupBean();
		CreateGroupCall creategroupCall = new CreateGroupCall();
		creategroupBean.setGroupName(groupname);
		creategroupBean.setSellerId(sellerid);
		creategroupCall.setData(false, creategroupBean);
		creategroupCall.callService();
		if (!creategroupCall.getString("code").equals("200")) {
			creategroupCall.callService();
		}
		return creategroupCall.getString("data");
	}
	/**
	 * livestatus 2 livePhase
	 * @param livestatus
	 * @return
	 */
	public static Integer getLivePhase(Integer livestatus){
		int livePhase=0;
		if(livestatus==0||livestatus==1){
			livePhase=10;
		}else if(livestatus==2||livestatus==3){
			livePhase=20;
		}else{
			livePhase=30;
		}
		return livePhase;
	}
	/**
	 * 解除直播禁言
	 * @param liveid
	 * @param sellerid
	 * @param uid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void CancelShutUpInLiveRoom(Integer liveid, Integer sellerid,Integer uid) throws ClientProtocolException, IOException {
		CancelShutUpInLiveRoomBean CancelShutUpInLiveRoomBean=new CancelShutUpInLiveRoomBean();
		CancelShutUpInLiveRoomCall CancelShutUpInLiveRoomCall=new CancelShutUpInLiveRoomCall();
		CancelShutUpInLiveRoomBean.setLiveId(liveid);
		CancelShutUpInLiveRoomBean.setSellerId(sellerid);
		CancelShutUpInLiveRoomBean.setUserId(uid);
		CancelShutUpInLiveRoomCall.setData(CancelShutUpInLiveRoomBean);
		CancelShutUpInLiveRoomCall.callService();		
	}
	/**
	 * 直播间禁言
	 * @param liveid
	 * @param sellerid
	 * @param uid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void ShutUpInLiveRoom(Integer liveid, Integer sellerid,Integer uid) throws ClientProtocolException, IOException {
		ShutUpInLiveRoomBean shutupinliveroomBean=new ShutUpInLiveRoomBean();
		ShutUpInLiveRoomCall shutupinliveroomCall=new ShutUpInLiveRoomCall();
		shutupinliveroomBean.setLiveId(liveid);
		shutupinliveroomBean.setSellerId(sellerid);
		shutupinliveroomBean.setUserId(uid);
		shutupinliveroomCall.setData(shutupinliveroomBean);
		shutupinliveroomCall.callService();		
	}
	
	/**
	 * 创建直播bean 初始化默认Createsellerlive参数
	 * 
	 * @return
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static CreateSellerPreVideoBean initCreatesellerPreVideoBean(Integer userId) throws InterruptedException, ClientProtocolException, IOException {
		if (userId==null || userId == 0 ) {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			userId = list.get(0).getUserId();
		}
		CreateSellerPreVideoBean createsellerprevideoBean = new CreateSellerPreVideoBean();
		// 默认码头直播
		createsellerprevideoBean.setPreVideoDto(new PreVideoDto());
		createsellerprevideoBean.getPreVideoDto().setUserId(userId);
		createsellerprevideoBean.getPreVideoDto().setCover("http://img.ymatou.com/app/flag/circle/France.png");
		createsellerprevideoBean.getPreVideoDto().setPreVideoHeight(100);
		createsellerprevideoBean.getPreVideoDto().setPreVideoLength(1500);
		createsellerprevideoBean.getPreVideoDto().setPreVideoPic("http://img.ymatou.com/app/flag/circle/France.png");
		createsellerprevideoBean.getPreVideoDto().setPreVideoWidth(200);
		createsellerprevideoBean.getPreVideoDto().setPreVideoUrl("http://v2.ymatou.com/uploads/20171024/f99192ff0f712310e7a39f43edb38f11.mp4");
		return createsellerprevideoBean;
	}
	
	
	/**
	 * 创建预告
	 */
	public static void CreatesellerPreVideo(CreateSellerPreVideoBean createsellerprevideoBean) throws InterruptedException, ClientProtocolException, IOException {
		CreateSellerPreVideoCall createsellerprevideoCall= new CreateSellerPreVideoCall();
		createsellerprevideoCall.setData(createsellerprevideoBean);
		createsellerprevideoCall.callService();			
		Logger.verifyEquals("200", createsellerprevideoCall.getString("Code"), "验证code");
	}
	
	/**
	 * 创建直播bean 初始化默认Createsellerlive参数
	 * 
	 * @return
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static CreateSellerLiveBean initCreatesellerliveBean(Userinfo uinfo) throws InterruptedException, ClientProtocolException, IOException {
		if (uinfo == null) {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			uinfo = list.get(0);
		}
		CreateSellerLiveBean createsellerliveBean = new CreateSellerLiveBean();
		LiveRoom livedto = new LiveRoom();
		// 默认码头直播
		livedto.setLiveType(0);
		livedto.setCountryId(1);
		livedto.setLiveDesc("默认直播简介"+TestDataManager.randomStr(30));;
		// 第三方创建较慢 使用模拟数据
		// livedto.setGroupId(CreateGroup("AutoTestGroup" +
		// TestDataManager.getRandomNum(1)));
		livedto.setGroupId(String.valueOf(YMTDateUtil.getDate().getTime()));
		livedto.setStartTime(YMTDateUtil.getBeforeOrNextMunite(30));
		livedto.setLatitude("31." + TestDataManager.getRandomNum(4));
		livedto.setLongitude("100." + TestDataManager.getRandomNum(4));
		livedto.setLiveAddress("live地址" + TestDataManager.getRandomNum(4));
		livedto.setLiveCover("http://img.ymatou.com/app/flag/circle/America.png");
		livedto.setLiveTitle("直播标题" + TestDataManager.getRandomNum(8));
		livedto.setShoppingAddress("ShoppingAddress:" + TestDataManager.getRandomNum(4));
		livedto.setPreVideoHeight(100);
		livedto.setPreVideoLength(1500);
		livedto.setPreVideoPic("http://img.ymatou.com/app/flag/circle/France.png");
		livedto.setPreVideoWidth(200);
		livedto.setPreVideoUrl("http://v2.ymatou.com/uploads/20171024/f99192ff0f712310e7a39f43edb38f11.mp4");
		livedto.setSellerName(uinfo.getLoginId());
		livedto.setUserId(uinfo.getUserId());
		livedto.setLiveCategoryId(1);
		createsellerliveBean.setLiveDto(livedto);
		createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
		return createsellerliveBean;
	}
	/**
	 * 用uid初始
	 * @param uid
	 * @return
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static CreateSellerLiveBean initCreatesellerliveBean(int uid) throws InterruptedException, ClientProtocolException, IOException {
		String loginid=new JUserWapper().selectUserinfoByUid(uid).get(0).getLoginId();
		CreateSellerLiveBean createsellerliveBean = new CreateSellerLiveBean();
		LiveRoom livedto = new LiveRoom();
		// 默认码头直播
		livedto.setLiveType(0);
		livedto.setCountryId(1);
		livedto.setLiveDesc("直播简介"+TestDataManager.randomStr(20));
		// 第三方创建较慢 使用模拟数据
		// livedto.setGroupId(CreateGroup("AutoTestGroup" +
		// TestDataManager.getRandomNum(1)));
		livedto.setGroupId(String.valueOf(YMTDateUtil.getDate().getTime()));
		//livedto.setStartTime(YMTDateUtil.getBeforeOrNextSecond(6));
		livedto.setStartTime(YMTDateUtil.getBeforeOrNextSecond(30));
		livedto.setLatitude("31." + TestDataManager.getRandomNum(4));
		livedto.setLongitude("100." + TestDataManager.getRandomNum(4));
		livedto.setLiveAddress("live地址" + TestDataManager.getRandomNum(4));
		livedto.setLiveCover("http://img.ymatou.com/app/flag/circle/America.png");
		livedto.setLiveTitle("直播标题" + TestDataManager.getRandomNum(8));
		livedto.setShoppingAddress("ShoppingAddress:" + TestDataManager.getRandomNum(4));
		livedto.setPreVideoHeight(100);
		livedto.setPreVideoLength(1500);
		
		livedto.setPreVideoPic("http://img.ymatou.com/app/flag/circle/France.png");
		livedto.setPreVideoWidth(200);
		livedto.setPreVideoUrl("http://v2.ymatou.com/uploads/20171024/f99192ff0f712310e7a39f43edb38f11.mp4");
		livedto.setSellerName(loginid);
		livedto.setUserId(uid);
		livedto.setLiveCategoryId(1);
		createsellerliveBean.setLiveDto(livedto);
		createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
		return createsellerliveBean;
	}
	/**
	 * 强制更新数据库时间为当前时间之前5分钟(开始)
	 * 
	 * @param liveid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void UpdateLiveTimeToStart(Integer liveid) throws ClientProtocolException, IOException {
		String time = YMTDateUtil.getBeforeOrNextMunite(-10);
		Logger.comment("更新开始时间:" + time);

		new LiveRoomWapper().updateLiveRoomTime(time, null,null, liveid);
	}

	/**
	 * 排序直播
	 * 
	 * @param liveid
	 * @param uid
	 * @param ProductIdList
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SortLiveProduct(Integer liveid, Integer uid, List<String> ProductIdList) throws ClientProtocolException, IOException {
		Logger.comment(liveid + ":主排序直播商品:uid:" + uid);
		SortLiveProductBean sortliveproductBean = new SortLiveProductBean();
		SortLiveProductCall sortliveproductCall = new SortLiveProductCall();
		sortliveproductBean.setUserId(uid);
		sortliveproductBean.setLiveId(liveid);
		sortliveproductBean.setProductIdList(ProductIdList);
		sortliveproductCall.setData(sortliveproductBean);
		sortliveproductCall.callService();
	}

	/**
	 * 强制主播上线,会修改开始时间
	 * 
	 * @param liveid
	 * @param uid
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SellerLiveOnline(Integer liveid, Integer uid) throws ClientProtocolException, IOException {
		UpdateLiveTimeToStart(liveid);
		Logger.comment(liveid + ":主播上线:uid:" + uid);
		SellerLiveOnlineBean sellerliveonlineBean = new SellerLiveOnlineBean();
		SellerLiveOnlineCall sellerliveonlineCall = new SellerLiveOnlineCall();
		sellerliveonlineBean.setLiveId(liveid);
		sellerliveonlineBean.setUserId(uid);
		sellerliveonlineCall.setData(sellerliveonlineBean);
		sellerliveonlineCall.callService();
	}

	public static void SellerLiveOnline(Integer liveid, Integer uid, boolean ut) throws ClientProtocolException, IOException {
		if (ut)
			UpdateLiveTimeToStart(liveid);
		Logger.comment(liveid + ":主播上线:uid:" + uid);
		SellerLiveOnlineBean sellerliveonlineBean = new SellerLiveOnlineBean();
		SellerLiveOnlineCall sellerliveonlineCall = new SellerLiveOnlineCall();
		sellerliveonlineBean.setLiveId(liveid);
		sellerliveonlineBean.setUserId(uid);
		sellerliveonlineCall.setData(sellerliveonlineBean);
		sellerliveonlineCall.callService();
	}

	public static void RemoveSellerLive(Integer liveid, Integer uid) throws ClientProtocolException, IOException {
		Logger.comment(liveid + ":删除直播:uid:" + uid);
		RemoveSellerLiveBean removesellerliveBean = new RemoveSellerLiveBean();
		RemoveSellerLiveCall removesellerliveCall = new RemoveSellerLiveCall();
		removesellerliveBean.setLiveId(liveid);
		removesellerliveBean.setUserId(uid);
		removesellerliveCall.setData(removesellerliveBean);
		removesellerliveCall.callService();
	}
	/**
	 * 设置公告
	 * @param liveid
	 * @param content
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SaveLiveNotice(Integer liveid,String content) throws ClientProtocolException, IOException{
		SaveLiveNoticeBean savelivenoticeBean=new SaveLiveNoticeBean();
		SaveLiveNoticeCall savelivenoticeCall=new SaveLiveNoticeCall();
		savelivenoticeBean.setContent(content);
		savelivenoticeBean.setLiveId(liveid);
		savelivenoticeBean.setOperator("autotest");
		savelivenoticeCall.setData(savelivenoticeBean);
		savelivenoticeCall.callService();			
	}
	/**
	 * 创建直播
	 * 
	 * @param createsellerliveBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static LiveRoom CreateSellerLive(CreateSellerLiveBean createsellerliveBean) throws ClientProtocolException, IOException, InterruptedException {
		return CreateSellerLive(createsellerliveBean, true);
	}
	/**
	 * 获取直播列表
	 * @param sellerid
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static JsonArray SellerlivelistCall(Integer sellerid) throws ClientProtocolException, IOException {
		SellerLiveListBean sellerlivelistBean=new SellerLiveListBean();
		SellerLiveListCall sellerlivelistCall=new SellerLiveListCall();
		sellerlivelistBean.setUserId(sellerid);
		sellerlivelistBean.setPageIndex(1);
		sellerlivelistBean.setPageSize(10);
		sellerlivelistCall.setData(sellerlivelistBean);
		sellerlivelistCall.callService();
		try {
		 return sellerlivelistCall.getJsonObject().get("Data").getAsJsonObject().get("LiveList").getAsJsonArray();
		}catch (Exception e) {
			return null;
		}
	}
	
	/**
	 * 创建直播录制任务
	 * 
	 * //@param createsellerliveBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static String CreateProductVideo(int liveId,int userId,String productId) throws ClientProtocolException, IOException, InterruptedException {
		CreateProductVideoBean createproductvideoBean=new CreateProductVideoBean();
		CreateProductVideoCall createproductvideoCall=new CreateProductVideoCall();
		createproductvideoBean.setLiveId(liveId);
		createproductvideoBean.setUserId(userId);
		createproductvideoBean.setProductId(productId);
		
		//增加mock，消除存量数据
		LinkedHashMap<String,Object> m=new LinkedHashMap<>();
		m.put("mock", "mock-enable");
		m.put("mockId-1", TestDataManager.getRandomUUID().toString());
		m.put("mockApi-1", "liveseller-createLiveRecord-Normal");
		String taskId = TestDataManager.getRandomNum(9);
		m.put("mockParam-1-taskId", taskId);
		PayGateWayCallService.addMock(createproductvideoCall, m);
		
		createproductvideoCall.setData(createproductvideoBean);
		createproductvideoCall.callService();			
		Logger.verifyEquals("200", createproductvideoCall.getString("Code"), "验证code");
	
		return taskId;
	}
	/**
	 * 可以指定taskid 用来模拟bug-taskid超出int最大长度
	 * @param liveId
	 * @param userId
	 * @param productId
	 * @param taskId
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static String CreateProductVideo(int liveId,int userId,String productId,String taskId) throws ClientProtocolException, IOException, InterruptedException {
		CreateProductVideoBean createproductvideoBean=new CreateProductVideoBean();
		CreateProductVideoCall createproductvideoCall=new CreateProductVideoCall();
		createproductvideoBean.setLiveId(liveId);
		createproductvideoBean.setUserId(userId);
		createproductvideoBean.setProductId(productId);
		
		//增加mock，消除存量数据
		LinkedHashMap<String,Object> m=new LinkedHashMap<>();
		m.put("mock", "mock-enable");
		m.put("mockId-1",TestDataManager.getRandomUUID().toString());
		m.put("mockApi-1", "liveseller-createLiveRecord-Normal");
		m.put("mockParam-1-taskId", taskId);
		PayGateWayCallService.addMock(createproductvideoCall, m);
		
		createproductvideoCall.setData(createproductvideoBean);
		createproductvideoCall.callService();			
		Logger.verifyEquals("200", createproductvideoCall.getString("Code"), "验证code");
	
		return taskId;
	}
	
	/**
	 * 终止直播录制任务
	 * 
	 * @param liveId
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static void StopProductVideo(int liveId,String productId) throws ClientProtocolException, IOException, InterruptedException {
		StopProductVideoBean stopproductvideoBean=new StopProductVideoBean();
		StopProductVideoCall stopproductvideoCall=new StopProductVideoCall();
		stopproductvideoBean.setLiveId(liveId);
		stopproductvideoBean.setProductId(productId);
		
		//增加mock，消除存量数据
		LinkedHashMap<String,Object> m=new LinkedHashMap<>();
		m.put("mock", "mock-enable");
		m.put("mockId-1", TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
		m.put("mockApi-1", "liveseller-stopLiveRecord-Normal");
		PayGateWayCallService.addMock(stopproductvideoCall, m);
		
		stopproductvideoCall.setData(stopproductvideoBean);
		stopproductvideoCall.callService();			
		Logger.verifyEquals("200", stopproductvideoCall.getString("Code"), "验证code");
	
	}
	
	
	/**
	 * 取消直播录制任务
	 * 
	 * @param liveId
	 * @param productId
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static void RemoveProductVideo(int liveId,String productId) throws ClientProtocolException, IOException, InterruptedException {
		RemoveProductVideoBean removeproductvideoBean=new RemoveProductVideoBean();
		RemoveProductVideoCall removeproductvideoCall=new RemoveProductVideoCall();
		removeproductvideoBean.setLiveId(liveId);
		removeproductvideoBean.setProductId(productId);
		//增加mock，消除存量数据
		LinkedHashMap<String,Object> m=new LinkedHashMap<>();
		m.put("mock", "mock-enable");
		m.put("mockId-1", TestDataManager.getRandomUUID().toString());
		m.put("mockApi-1", "liveseller-stopLiveRecord-Normal");
		PayGateWayCallService.addMock(removeproductvideoCall, m);
		removeproductvideoCall.setData(removeproductvideoBean);
		removeproductvideoCall.callService();			
		Logger.verifyEquals("200", removeproductvideoCall.getString("Code"), "验证code");
	}
	
	
	/**
	 * 查询待讲解商品列表
	 * 
	 * @param liveId
	 * @return 
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static JsonArray GetUnExplainProductList(int liveId) throws ClientProtocolException, IOException, InterruptedException {
		GetUnExplainProductListBean getunexplainproductlistBean = new GetUnExplainProductListBean();
		GetUnExplainProductListCall getunexplainproductlistCall = new GetUnExplainProductListCall();
		getunexplainproductlistBean.setLiveId(liveId);
		getunexplainproductlistBean.setIsTimeOrExplainNum(true);
		getunexplainproductlistCall.setData(getunexplainproductlistBean);
		getunexplainproductlistCall.callService();
		JsonArray asJsonArray = getunexplainproductlistCall.getJsonObject().getAsJsonObject("Data").getAsJsonArray("UnExplainProductList");
	
		return asJsonArray;
	}
	

	/**
	 * 订阅直播App
	 * 
	 * @param liveid
	 * @param userid
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static void SubscribeLive(Integer liveid, Integer userid) throws ClientProtocolException, IOException, InterruptedException {
		SubscribeBean subscribeBean = new SubscribeBean();
		SubscribeCall subscribeCall = new SubscribeCall();
		subscribeBean.setLiveId(liveid);
		subscribeBean.setUserId(userid);
		subscribeCall.setData(subscribeBean);
		subscribeCall.callService();
	}

	/**
	 * 订阅直播WxApp
	 *
	 * @param liveid
	 * @param userid
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static void SubscribeLiveWx(Integer liveid, Integer userid) throws ClientProtocolException, IOException, InterruptedException {
		SubscribeBean subscribeBean = new SubscribeBean();
		SubscribeCall subscribeCall = new SubscribeCall();
		subscribeBean.setLiveId(liveid);
		subscribeBean.setUserId(userid);
		subscribeBean.setSource(1);
		subscribeBean.setFormId(YMTDateUtil.getBeforeOrNextDay(0));
		subscribeCall.setData(subscribeBean);
		subscribeCall.callService();
	}

	/**
	 * 取消订阅直播App
	 * 
	 * @param liveid
	 * @param userid
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static void UnSubscribeLive(Integer liveid, Integer userid) throws ClientProtocolException, IOException, InterruptedException {
		UnSubscribeBean unsubscribeBean = new UnSubscribeBean();
		UnSubscribeCall unsubscribeCall = new UnSubscribeCall();
		unsubscribeBean.setLiveId(liveid);
		unsubscribeBean.setUserId(userid);
		unsubscribeCall.setData(unsubscribeBean);
		unsubscribeCall.callService();
	}

	/**
	 * 取消订阅直播WxApp
	 *
	 * @param liveid
	 * @param userid
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static void UnSubscribeLiveWx(Integer liveid, Integer userid) throws ClientProtocolException, IOException, InterruptedException {
		UnSubscribeBean unsubscribeBean = new UnSubscribeBean();
		UnSubscribeCall unsubscribeCall = new UnSubscribeCall();
		unsubscribeBean.setLiveId(liveid);
		unsubscribeBean.setUserId(userid);
		unsubscribeCall.setData(unsubscribeBean);
		unsubscribeCall.callService();
	}

	/**
	 * 添加商品到直播
	 * 
	 * @param liveid
	 *            liveid
	 * @param userid
	 *            sellerid
	 * @param pid
	 *            productid
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static void AddProductsToLive(Integer liveid, Integer userid, String pid) throws ClientProtocolException, IOException {
		Logger.comment(liveid + ":添加商品:pid:" + pid);
		AddProductsToLiveBean addproductstoliveBean = new AddProductsToLiveBean();
		AddProductsToLiveCall addproductstoliveCall = new AddProductsToLiveCall();
		addproductstoliveBean.setLiveId(liveid);
		List<String> ProductIdList = new ArrayList<>();
		ProductIdList.add(pid);
		addproductstoliveBean.setProductIdList(ProductIdList);
		addproductstoliveBean.setUserId(userid);
		addproductstoliveCall.setData(false, addproductstoliveBean);
		addproductstoliveCall.callService();
	}
	
	
	

	/**
	 * 重载 批量添加
	 * 
	 * @param liveid
	 * @param userid
	 * @param ProductIdList
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void AddProductsToLive(Integer liveid, Integer userid, List<String> ProductIdList) throws ClientProtocolException, IOException {
		Logger.comment(liveid + ":添加商品:ProductIdList:" + ProductIdList);
		AddProductsToLiveBean addproductstoliveBean = new AddProductsToLiveBean();
		AddProductsToLiveCall addproductstoliveCall = new AddProductsToLiveCall();
		addproductstoliveBean.setLiveId(liveid);
		addproductstoliveBean.setProductIdList(ProductIdList);
		addproductstoliveBean.setUserId(userid);
		addproductstoliveCall.setData(false, addproductstoliveBean);
		addproductstoliveCall.callService();
	}
	
	/**
	 * 重载 运营端批量添加
	 * 
	 * @param liveid
	 * @param userid
	 * @param ProductIdList
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void AddProductsToLiveByAdmin(Integer liveid, Integer userid, List<String> ProductIdList) throws ClientProtocolException, IOException {
		Logger.comment(liveid + ":添加商品:ProductIdList:" + ProductIdList);
		AddProductsToLiveByAdminBean addproductstoliveByAdminBean = new AddProductsToLiveByAdminBean();
		AddProductsToLiveByAdminCall addproductstoliveByAdminCall = new AddProductsToLiveByAdminCall();
		addproductstoliveByAdminBean.setLiveId(liveid);
		addproductstoliveByAdminBean.setProductIdList(ProductIdList);
		addproductstoliveByAdminCall.setData(false, addproductstoliveByAdminBean);
		addproductstoliveByAdminCall.callService();
	}
	

	/**
	 * 设置置顶商品
	 * 
	 * @param liveid
	 * @param pid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SetLiveProductTop(Integer liveid, String pid) throws ClientProtocolException, IOException {
		SetLiveProductTopBean setliveproducttopBean = new SetLiveProductTopBean();
		SetLiveProductTopCall setliveproducttopCall = new SetLiveProductTopCall();
		setliveproducttopBean.setLiveId(liveid);
		setliveproducttopBean.setProductId(pid);
		setliveproducttopCall.setData(setliveproducttopBean);
		setliveproducttopCall.callService();
	}

	/**
	 * 关闭直播 慎用
	 * 
	 * @param liveid
	 * @param userid
	 * @param type
	 *            7 - 系统自动关闭直播，8 - 关闭直播，9 - 结束直播，10 - 强制关停<br>
	 *            7需要结束时间超过当前时间且断流<br>
	 *            8需要没有推流过<br>
	 *            9需要推流过而且当前时间超过开始时间<br>
	 *            10<br>
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void CloseSellerLive(Integer liveid, Integer userid, Integer type) throws ClientProtocolException, IOException {
		Logger.comment(liveid + ":关闭直播:type:" + type);
		if (type.equals(8)) {
			CloseSellerLiveBean closesellerliveBean = new CloseSellerLiveBean();
			CloseSellerLiveCall closesellerliveCall = new CloseSellerLiveCall();
			closesellerliveBean.setLiveId(liveid);
			closesellerliveBean.setUserId(userid);
			closesellerliveBean.setCloseType("CloseLive");
			closesellerliveCall.setData(false, closesellerliveBean);
			closesellerliveCall.callService();
		} else if (type.equals(9)) {
			CloseSellerLiveBean closesellerliveBean = new CloseSellerLiveBean();
			CloseSellerLiveCall closesellerliveCall = new CloseSellerLiveCall();
			closesellerliveBean.setLiveId(liveid);
			closesellerliveBean.setUserId(userid);
			closesellerliveBean.setCloseType("FinishLive");
			closesellerliveCall.setData(false, closesellerliveBean);
			closesellerliveCall.callService();
		}
	}

	/**
	 * 自动关闭用户的全部直播
	 * 
	 * @param uid
	 * @throws IOException
	 * @throws ClientProtocolException
	 * @throws InterruptedException
	 */
	public static void AutoCloseLiveRoomByUserId(Integer uid) throws ClientProtocolException, IOException, InterruptedException {
		List<LiveRoom> roomlist = new LiveRoomWapper().selectRunningLiveRoomByUserid(uid);

		for (LiveRoom liveRoom : roomlist) {
			LiveRoomWapper liveRoomWapper = new LiveRoomWapper();
			liveRoomWapper.updateLiveRoomTime(YMTDateUtil.getBeforeOrNextMunite(-100), YMTDateUtil.getBeforeOrNextMunite(-50),YMTDateUtil.getBeforeOrNextMunite(-50) ,liveRoom.getId());
			CloseSellerLiveBean closesellerliveBean = new CloseSellerLiveBean();
			CloseSellerLiveCall closesellerliveCall = new CloseSellerLiveCall();
			closesellerliveBean.setLiveId(liveRoom.getId());
			closesellerliveBean.setUserId(uid);
			if (liveRoom.getLivePush() == 0) {
				Logger.comment(liveRoom.getId() + ":已有直播自动关闭");
				closesellerliveBean.setCloseType("CloseLive");
			} else if (liveRoom.getLivePush() == 1) {
				Logger.comment(liveRoom.getId() + "已有直播自动结束");
				closesellerliveBean.setCloseType("FinishLive");
			}
			closesellerliveCall.setData(false, closesellerliveBean);
			closesellerliveCall.callService();
			if (closesellerliveCall.getStatusCode()!=200||!closesellerliveCall.getString("Code").equals("200")) {
				//失败的话直接改成action -1
				liveRoomWapper.updateLiveRoomAction(liveRoom.getId(), -1);
//				SysCloseLive(liveRoom.getId());
			}
		}
	}

	/**
	 * 创建直播
	 * 
	 * @param createsellerliveBean
	 * @param autoclose
	 *            是否自动关闭已存在直播
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static LiveRoom CreateSellerLive(CreateSellerLiveBean createsellerliveBean, boolean autoclose) throws ClientProtocolException, IOException, InterruptedException {
		Logger.comment("创建直播:autoclose:" + autoclose);
		if (autoclose) {
			AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
		}
		CreateSellerLiveCall createsellerliveCall = new CreateSellerLiveCall();
		createsellerliveCall.setData(false, createsellerliveBean);
		createsellerliveCall.callService();
		int liveid = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject().get("LiveId").getAsInt();
		
		LiveRoom dblive = new LiveRoomWapper().selectLiveRoomById(liveid);
		System.out.println(dblive.getStartTime());
		dblive.setStartTime(dblive.getStartTime().substring(0, 19));
		System.out.println(dblive.getStartTime());
		return dblive;
	}

	/**
	 * 创建live 基本调用
	 * 
	 * @param createsellerliveBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static CreateSellerLiveCall CreateLive(CreateSellerLiveBean createsellerliveBean) throws ClientProtocolException, IOException {
		CreateSellerLiveCall createsellerliveCall = new CreateSellerLiveCall();
		createsellerliveCall.setData(false, createsellerliveBean);
		createsellerliveCall.callService();
		return createsellerliveCall;
	}

	/**
	 * 加入群
	 * 
	 * @param liveid
	 * @param userId
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void enterGroup(int liveid, int userId) throws InterruptedException, ClientProtocolException, IOException {
		Logger.comment(liveid + ":加入群:uid:" + userId);
		EnterGroupBean enterGroupBean = new EnterGroupBean();
		EnterGroupCall enterGroupCall = new EnterGroupCall();
		enterGroupBean.setLiveId(liveid);
		enterGroupBean.setUserId(userId);
		enterGroupCall.setData(false, enterGroupBean);
		enterGroupCall.callService();
	}

	/**
	 * 退出群
	 * 
	 * @param liveid
	 * @param userId
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void quitGroup(int liveid, int userId) throws InterruptedException, ClientProtocolException, IOException {
		Logger.comment(liveid + ":退出群:uid:" + userId);
		QuitGroupBean quitGroupBean = new QuitGroupBean();
		QuitGroupCall quitGroupCall = new QuitGroupCall();
		quitGroupBean.setLiveId(liveid);
		quitGroupBean.setUserId(userId);
		quitGroupCall.setData(false, quitGroupBean);
		quitGroupCall.callService();
	}

	/**
	 * 增加/获取比心数
	 * 
	 * @param liveid
	 * @param userId
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static int getLikeCount(int liveid, int userId, int count) throws ClientProtocolException, IOException {
		Logger.comment(liveid + ":比心:count:" + count);
		LikeBean likeBean = new LikeBean();
		LikeCall likeCall = new LikeCall();
		likeBean.setLiveId(liveid);
		likeBean.setUserId(userId);
		likeBean.setCount(count);
		likeCall.setData(false, likeBean);
		likeCall.callService();
		return likeCall.getJsonObject().get("data").getAsJsonObject().get("totalCount").getAsInt();
	}

	/**
	 * 暂停销售
	 * 
	 * @param liveid
	 * @param pid
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SuspendLiveProduct(int liveid, String pid) throws ClientProtocolException, IOException {
		Logger.comment(liveid + ":暂停销售:pid:" + pid);
		SuspendLiveProductBean suspendliveproductBean = new SuspendLiveProductBean();
		SuspendLiveProductCall suspendliveproductCall = new SuspendLiveProductCall();
		suspendliveproductBean.setLiveId(liveid);
		suspendliveproductBean.setProductId(pid);
		suspendliveproductCall.setData(false, suspendliveproductBean);
		suspendliveproductCall.callService();
	}

	/**
	 * 恢复销售
	 * 
	 * @param liveid
	 * @param pid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void ResumeLiveProduct(int liveid, String pid) throws ClientProtocolException, IOException {
		Logger.comment(liveid + ":恢复销售:pid:" + pid);
		ResumeLiveProductBean resumeliveproductBean = new ResumeLiveProductBean();
		ResumeLiveProductCall resumeliveproductCall = new ResumeLiveProductCall();
		resumeliveproductBean.setLiveId(liveid);
		List<String> ProductIdList = new ArrayList<>();
		ProductIdList.add(pid);
		resumeliveproductBean.setProductIds(ProductIdList);
		resumeliveproductCall.setData(resumeliveproductBean);
		resumeliveproductCall.callService();
	}

	/**
	 * @param liveid
	 * @param pid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void RemoveLiveProduct(int liveid, String pid) throws ClientProtocolException, IOException {
		Logger.comment(liveid + ":移除商品:pid:" + pid);
		RemoveLiveProductBean removeliveproductBean = new RemoveLiveProductBean();
		RemoveLiveProductCall removeliveproductCall = new RemoveLiveProductCall();
		removeliveproductBean.setLiveId(liveid);
		removeliveproductBean.setProductId(pid);
		removeliveproductCall.setData(false, removeliveproductBean);
		removeliveproductCall.callService();
	}

	/**
	 * 产线用数据
	 * 
	 * @param userid
	 * @param loginid
	 * @return
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static CreateSellerLiveBean initOnlineCreatesellerliveBean(Integer userid, String loginid) throws InterruptedException, ClientProtocolException, IOException {
		CreateSellerLiveBean createsellerliveBean = new CreateSellerLiveBean();
		LiveRoom livedto = new LiveRoom();
		livedto.setCountryId(1);
		// 第三方创建较慢 使用模拟数据
		// livedto.setGroupId(CreateGroup("AutoTestGroup" +
		// TestDataManager.getRandomNum(1)));
		livedto.setGroupId(CreateGroup("AutoTestGroup",userid));
		livedto.setStartTime(YMTDateUtil.getBeforeOrNextMunite(1));
		livedto.setLatitude("31." + TestDataManager.getRandomNum(4));
		livedto.setLongitude("100." + TestDataManager.getRandomNum(4));
		livedto.setLiveAddress("live地址");
		livedto.setLiveCover("http://s2.ymatou.com/login/5aebbf5a6893bd825441a68a60b42b51.jpg");
		livedto.setLiveTitle("AT测试直播STG标题1");
		livedto.setLiveDesc("直播简介");
		livedto.setShoppingAddress("上海");
		livedto.setPreVideoHeight(100);
		livedto.setPreVideoLength(1500);
		livedto.setPreVideoPic("http://s2.ymatou.com/login/5aebbf5a6893bd825441a68a60b42b51.jpg");
		livedto.setPreVideoWidth(200);
		livedto.setPreVideoUrl("http://v2.ymatou.com/uploads/20171024/f99192ff0f712310e7a39f43edb38f11.mp4");
		livedto.setSellerName(loginid);
		livedto.setUserId(userid);
		livedto.setLiveCategoryId(1);
		livedto.setLiveType(0);
		createsellerliveBean.setLiveDto(livedto);
		createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
		return createsellerliveBean;
	}

	/**
	 * @param liveid
	 * @param userid
	 * @param tabindex
	 * @return
	 * @throws InterruptedException
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static LiveProductListCall GetLiveProductList(Integer liveid, Integer userid, int tabindex) throws InterruptedException, ClientProtocolException, IOException {
		LiveProductListBean liveproductlistBean = new LiveProductListBean();
		LiveProductListCall liveproductlistCall = new LiveProductListCall();
		liveproductlistBean.setLiveId(liveid);
		liveproductlistBean.setUserId(userid);
		liveproductlistBean.setTabIndex(tabindex);
		liveproductlistCall.setData(liveproductlistBean);
		liveproductlistCall.callService();
		return liveproductlistCall;
	}

	public static void main(String[] args) throws Exception {
		// 产线数据准备
		// 商品数据 来自app的sqlserver integratedproduct库
		// select sProductId,iUserId from ymt_products where sproduct =
		// 'ceshiwupai' and ibrandid = 11634 and daddtime<GetDate() and daddtime
		// >2017/10/24 and iuserid=21158951

		Integer userid = 21158951;
		String uname = "sstest2";
		CreateSellerLiveBean initcreatebean = LiveRoomCallService.initOnlineCreatesellerliveBean(userid, uname);
		CreateSellerLiveCall createsellerliveCall = LiveRoomCallService.CreateLive(initcreatebean);
		int liveid = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject().get("LiveId").getAsInt();
		List<String> ProductIdList = new ArrayList<>();
		ArrayList<String> list = TestDataManager.getLines("data");
		int count = 0;
		for (String line : list) {
			String[] ss = line.split("	");
			if (ss[1].equals(userid.toString()) && count < 20) {
				ProductIdList.add(ss[0]);
				count++;
			}
		}
		LiveRoomCallService.AddProductsToLive(liveid, userid, ProductIdList);
		Thread.sleep(60000 * 2);
		LiveRoomCallService.SellerLiveOnline(liveid, userid, false);
		LiveRoomCallService.SetLiveProductTop(liveid, ProductIdList.get(0));
	}

	/**
	 * 录制直播
	 * @param id
	 * @param file_id
	 * @return
	 */
	public static ReplayNotifyBean initReplayNotifyBean(Integer id, String file_id) {
		ReplayNotifyBean rb = new ReplayNotifyBean();

		MetaData metaData = new MetaData();
		Drm drm = new Drm();
		List<Trancode> processTaskList = new ArrayList<Trancode>();
		ProcedureStateChanged pc = new ProcedureStateChanged();
		rb.setEventType("ProcedureStateChanged");// 需要校验
		rb.setVersion("4.0");
		rb.setData(pc);
		pc.setErrCode(0);// 需要校验
		pc.setFileId(file_id);// 需要校验
		pc.setMessage("");
		pc.setMetaData(metaData);
		pc.setStatus("FINISH");
		pc.setDrm(drm);
		pc.setProcessTaskList(processTaskList);
		Trancode e = new Trancode();
		e.setTaskType("Transcode");// 需要校验
		e.setErrCode(0);// 需要校验
		e.setStatus("SUCCESS");// 需要校验
		TrancodeInPut input = new TrancodeInPut();
		input.setDefinition(220);// 需要校验
		e.setInput(input);
		TrancodeOutPut output = new TrancodeOutPut();
		output.setUrl("http://" + AppId + ".vod2.myqcloud.com/" + id + "/f20.hls");// 需要校验
		output.setContainer("hls");// 需要校验
		e.setOutput(output);
		processTaskList.add(e);
		return rb;
	}
	/**
	 * 录制商品讲解直播
	 * @param id
	 * @param file_id
	 * @return
	 */
	public static ReplayNotifyBean initAskProductReplayNotifyBean(Integer id, String file_id) {
		ReplayNotifyBean rb = new ReplayNotifyBean();

		MetaData metaData = new MetaData();
		Drm drm = new Drm();
		List<Trancode> processTaskList = new ArrayList<Trancode>();
		ProcedureStateChanged pc = new ProcedureStateChanged();
		rb.setEventType("ProcedureStateChanged");// 需要校验
		rb.setVersion("4.0");
		rb.setData(pc);
		pc.setErrCode(0);// 需要校验
		pc.setFileId(file_id);// 需要校验
		pc.setMessage("");
		pc.setMetaData(metaData);
		pc.setStatus("FINISH");
		pc.setDrm(drm);
		pc.setProcessTaskList(processTaskList);
		Trancode e = new Trancode();
		e.setTaskType("Transcode");// 需要校验
		e.setErrCode(0);// 需要校验
		e.setStatus("SUCCESS");// 需要校验
		TrancodeInPut input = new TrancodeInPut();
		input.setDefinition(220);// 需要校验
		e.setInput(input);
		TrancodeOutPut output = new TrancodeOutPut();
		output.setUrl("http://" + AppId + ".vod2.myqcloud.com/" + id + "/f10.mp4");// 需要校验
		output.setContainer("mp4");// 需要校验--mp4为商品
		e.setOutput(output);
		processTaskList.add(e);
		
		Trancode e2 = new Trancode();
		e2.setTaskType("AnimatedGraphics");// 需要校验
		e2.setErrCode(0);// 需要校验
		e2.setStatus("SUCCESS");// 需要校验
		TrancodeInPut input2 = new TrancodeInPut();
		input2.setDefinition(220);// 需要校验
		e2.setInput(input2);
		TrancodeOutPut output2 = new TrancodeOutPut();
		output2.setUrl("http://" + AppId + ".vod2.myqcloud.com/" + id + "/f20.gif");// 需要校验
		output2.setContainer("gif");// 需要校验
		e2.setOutput(output2);
		processTaskList.add(e2);
		
		

		Trancode e3 = new Trancode();
		e3.setTaskType("CoverBySnapshot");// 需要校验
		e3.setErrCode(0);// 需要校验
		e3.setStatus("SUCCESS");// 需要校验
		TrancodeInPut input3 = new TrancodeInPut();
		input3.setDefinition(220);// 需要校验
		e3.setInput(input3);
		TrancodeOutPut output3 = new TrancodeOutPut();
		output3.setImageUrl("http://" + AppId + ".vod2.myqcloud.com/" + id + "/coverBySnapshot/c10.jpg");// 需要校验
//		output3.setContainer("hls");// 需要校验
		e3.setOutput(output3);
		processTaskList.add(e3);
		return rb;
	}
	/**
	 * 初始化创建秒杀 默认1分钟
	 * @param liveid 直播id
	 * @param catalogid 规格
	 * @param aprice 秒杀价
	 * @param astock 秒杀库存
	 * @param starttime 开始时间
	 * @return
	 * @throws InterruptedException
	 */
	public static CreateLiveActivityBean initCreateLiveActivityBean(Integer liveid,String catalogid,Double aprice,Integer astock,Date starttime) throws InterruptedException{
		CreateLiveActivityBean createliveactivityBean=new CreateLiveActivityBean();
		LiveActivityDto LiveActivity=new LiveActivityDto();
		List<ActivityProductDto> ActivityProducts=new ArrayList<>();
		ActivityProductDto apd=new ActivityProductDto();
		apd.setActivityPrice(aprice);
		apd.setActivityStock(astock);
		apd.setCatalogId(catalogid);
		apd.setProductId(ProductManagerCallServiceV2.getProductId(catalogid));
		ActivityProducts.add(apd);
		LiveActivity.setActivityProducts(ActivityProducts);
		LiveActivity.setLiveId(liveid);
		Integer sellerId=new LiveRoomWapper().selectLiveRoomById(liveid).getUserId();
		LiveActivity.setSellerId(sellerId);
		createliveactivityBean.setLiveActivity(LiveActivity);
		LiveActivity.setStartTime(String.valueOf(starttime.getTime()+4000));
		LiveActivity.setEndTime(String.valueOf(starttime.getTime()+100*60*1000));
		return createliveactivityBean;
	}
	/**使用创建活动初始化
	 * 查询的liveacctivityid是最新的一个所以要在创建后就初始化，否则会找错
	 * 只会对list ActivityProducts 的第一个设置LiveActivityProductId
	 * @param createliveactivityBean
	 * @return
	 * @throws InterruptedException
	 */
	public static ModifyLiveActivityBean initModifyLiveActivityBean(CreateLiveActivityBean createliveactivityBean) throws InterruptedException{
		ModifyLiveActivityBean ModifyLiveActivityBean=new ModifyLiveActivityBean();
		LiveActivityDto LiveActivity=createliveactivityBean.getLiveActivity();
		LiveRoomWapper LiveRoomWapper = new LiveRoomWapper();
		Integer liveacctivityid = LiveRoomWapper.selectLiveactivityByLiveId(createliveactivityBean.getLiveActivity().getLiveId()).get(0).getLiveActivityId();
		LiveActivity.setLiveActivityId(liveacctivityid);
		Integer LiveActivityProductId = LiveRoomWapper.selectLiveactivityproduct(liveacctivityid, LiveActivity.getActivityProducts().get(0).getProductId()).get(0).getLiveActivityProductId();
		LiveActivity.getActivityProducts().get(0).setActivityProductId(LiveActivityProductId);
		ModifyLiveActivityBean.setLiveActivity(LiveActivity);
		return ModifyLiveActivityBean;
	}
	/**
	 * 创建秒杀
	 * @param createliveactivityBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void CreateLiveActivity(CreateLiveActivityBean createliveactivityBean) throws ClientProtocolException, IOException {
		Logger.comment("创建秒杀活动");
		CreateLiveActivityCall createliveactivityCall=new CreateLiveActivityCall();
		createliveactivityCall.setData(createliveactivityBean);
		createliveactivityCall.callService();
	}
	/**
	 * 设置全局禁言100s
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void SetNotSpeeking(Integer userId,Integer second,Integer liveid) throws ClientProtocolException, IOException {
		SetNotSpeekingBean setnotspeekingBean=new SetNotSpeekingBean();
		SetNotSpeekingCall setnotspeekingCall=new SetNotSpeekingCall();
		setnotspeekingBean.setUserId(userId);
		setnotspeekingBean.setGroupNoSpeakingSecond(second);
		setnotspeekingBean.setReason("reason");
		setnotspeekingBean.setOperator("autotest");
		setnotspeekingBean.setLiveId(liveid);
		setnotspeekingCall.setData(false,setnotspeekingBean);
		setnotspeekingCall.callService();			
	}
	/**
	 * 解除禁言
	 * @param userid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void DisableNotSpeaking(Integer userid) throws ClientProtocolException, IOException {
		Integer id=getSpeakingNotAllowedId(userid);
		if(id<=0) {
			return;
		}
		DisableNotSpeakingBean disablenotspeakingBean=new DisableNotSpeakingBean();
		DisableNotSpeakingCall disablenotspeakingCall=new DisableNotSpeakingCall();
		disablenotspeakingBean.setNoSpeakingId(id);
		disablenotspeakingBean.setOperator("autotest");
		disablenotspeakingBean.setUserId(userid);
		disablenotspeakingCall.setData(disablenotspeakingBean);
		disablenotspeakingCall.callService();
	}
	/**
	 * 查询禁言id 如果没返回0
	 * @param userId
	 * @return
	 */
	public static  Integer getSpeakingNotAllowedId(Integer userId) {
//		LiveRoomWapper.selectSpeakingNotAllowed(userId).stream().filter(sp->(sp.getState().));
		Integer id=0;
		try {
		 id=new LiveRoomWapper().selectSpeakingNotAllowed(userId,0).stream().filter(sp->(sp.getState()==0&&sp.getEndTime().after(YMTDateUtil.getDate()))).findFirst().get().getId();
		}catch (Exception e) {
		}
		return id;
	}
	/**
	 * 求讲解
	 * @param liveid
	 * @param pid
	 * @param uid
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void AskProductVideo(Integer liveid,String pid,Integer uid) throws ClientProtocolException, IOException {
		AskProductVideoBean askproductvideoBean=new AskProductVideoBean();
		AskProductVideoCall askproductvideoCall=new AskProductVideoCall();
		askproductvideoBean.setLiveId(liveid);
		askproductvideoBean.setProductId(pid);
		//普通用户id 暂时无用
		askproductvideoBean.setUserId(uid);
		askproductvideoCall.setData(askproductvideoBean);
		askproductvideoCall.callService();		
	}
	/**
	 * 查询直播商品信息
	 * @param pid
	 * @param liveid
	 * @return 
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static JsonArray QueryProductlistCall(String pid,Integer liveid) throws ClientProtocolException, IOException {
		QueryProductsInLiveRoomBean queryproductsinliveroomBean=new QueryProductsInLiveRoomBean();
		QueryProductsInLiveRoomCall queryproductsinliveroomCall=new QueryProductsInLiveRoomCall();
		List<String> productIds=new ArrayList<>();
		productIds.add(pid);
		queryproductsinliveroomBean.setLiveId(liveid);
		queryproductsinliveroomBean.setProductIds(productIds);
		queryproductsinliveroomCall.setData(queryproductsinliveroomBean);
		queryproductsinliveroomCall.callService();		
		return queryproductsinliveroomCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("liveProductList");
	}
	
	/**
	 * 创建model
	 * @param userid
	 * @param height
	 * @param weight
	 * @param nick
	 * @return id
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static int CreateModelCall(Integer userid,Integer height,Integer weight,String nick) throws ClientProtocolException, IOException {
		CreateModelBean createmodelBean=new CreateModelBean();
		CreateModelCall createmodelCall=new CreateModelCall();
		createmodelBean.setHeight(height);
		createmodelBean.setWeight(weight);
		createmodelBean.setUserId(userid);
		createmodelBean.setNickName(nick);
		createmodelCall.setData(createmodelBean);
		createmodelCall.callService();			
		int id=Integer.valueOf( createmodelCall.getString("Data"));
		return id;
	}
	/**
	 * 从数据库删除用户的所有model
	 * @param userid
	 */
	public static void DeleteModel(int userid) {
		new LiveRoomWapper().deleteModelByUserId(userid);
	}
	/**
	 * 删除指定model
	 * @param id
	 * @param userid
	 */
	public static void DeleteModelById(int id,int userid) throws ClientProtocolException, IOException{
		DeleteModelBean deletemodelBean=new DeleteModelBean();
		DeleteModelCall deletemodelCall=new DeleteModelCall();
		deletemodelBean.setModelId(id);
		deletemodelBean.setUserId(userid);
		deletemodelCall.setData(deletemodelBean);
		deletemodelCall.callService();	
	}
	/**设置直播间的模特
	 * @param liveid
	 * @param list
	 */
	public static void SetLiveModel(int liveid,List<Integer> list) throws ClientProtocolException, IOException{
		SetLiveModelBean setlivemodelBean=new SetLiveModelBean();
		SetLiveModelCall setlivemodelCall=new SetLiveModelCall();
		setlivemodelBean.setLiveId(liveid);
		setlivemodelBean.setModelIds(list);
		setlivemodelCall.setData(setlivemodelBean);
		setlivemodelCall.callService();			
	}
}
